package com.liliya.servlet.cate;

import com.liliya.pojo.Cate;
import com.liliya.pojo.SubCate;
import com.liliya.service.CateService;
import com.liliya.service.SubCateService;
import com.liliya.service.impl.CateServiceImpl;
import com.liliya.service.impl.SubCateServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Description TODO
 * @Author hhy
 * @Date 2021/1/9 19:45
 */
@WebServlet(urlPatterns = "/subcate/del")
public class SubCateDelServlet extends HttpServlet {
    private SubCateService subCateService = new SubCateServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String subcatnum = req.getParameter("subcatnum");
        SubCateServiceImpl subCateService = new SubCateServiceImpl();
        CateServiceImpl cateService = new CateServiceImpl();
        SubCate subCate = subCateService.findSubCateByNum(Integer.parseInt(subcatnum));
        Cate cate = cateService.findCateByNum(subCate.getCatenum());

        req.getSession().setAttribute("subCate",subCate);
        req.getSession().setAttribute("cate",cate);
        resp.sendRedirect(req.getContextPath()+"/cate/subcatedel.jsp");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String subcatnum = req.getParameter("subcatnum");
        if (subcatnum!=null){
            subCateService.deleteSubCate(Integer.parseInt(subcatnum));
        }

        resp.sendRedirect(req.getContextPath()+"/cate/subcatemanage.jsp");

    }
}
